package com.katze.boot.system.controller;

import com.katze.boot.plugins.shiro.annotations.RestControllerMapping;
import com.katze.boot.plugins.shiro.annotations.RestRequestMapping;
import com.katze.boot.system.domain.SysUri;
import com.katze.boot.system.service.UriService;
import com.katze.common.Message;
import com.katze.common.Pagination;
import com.katze.common.controller.BaseController;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.Date;
import java.util.List;

@RestControllerMapping("/setting")
public class SettingController extends BaseController {

    @Autowired
    private UriService uriService;

    @RestRequestMapping(value = "/uri", permits = "uri:view", skip = true)
    public Message uriList (Pagination pagination, SysUri uri) {
        return toDataTable(this.uriService.findUris(pagination, uri));
    }

    @RestRequestMapping(value = "/uri/trim",  skip = true)
    public Message uriList (String category) {
        List<SysUri> list = this.uriService.findUrisByCategory(category);
        return Message.ok().data(list);
    }

    @RestRequestMapping(value = "/uri", method = RequestMethod.POST, desc = "新增URI", permits = "uri:add")
    public Message addUri (SysUri uri) {
        uri.setCreateTime(new Date());
        this.uriService.save(uri);
        return  Message.ok("新增成功").data(uri);
    }

    @RestRequestMapping(value = "/uri", method = RequestMethod.PUT, desc = "修改URI", permits = "uri:update")
    public Message updateUri (SysUri uri) {
        this.uriService.updateById(uri);
        return  Message.ok("修改成功");
    }


    @RestRequestMapping(value = "/uri", method = RequestMethod.DELETE, desc = "删除URI")
    public Message deleteUri (String id) {
        this.uriService.removeById(id);
        return Message.ok("删除成功");
    }
}
